<html>
<!--
 Copyright (C) 2017, 2020 XStream committers.
 All rights reserved.
 
 The software in this package is published under the terms of the BSD
 style license a copy of which has been included with this distribution in
 the LICENSE.txt file.
 
 Created on 25. April 2017 by Joerg Schaible
 -->
  <head>
    <title>CVE-2017-7957</title>
  </head>
  <body>

    <h2 id="vulnerability">Vulnerability</h2>
    
    <p>CVE-2017-7957: XStream can cause a Denial of Service when unmarshalling void.</p>
	
    <h2 id="affected_versions">Affected Versions</h2>
    
	<p>All versions until and including version 1.4.9 are affected, but <a href="#workarounds">workarounds</a> exist.</p>

    <h2 id="description">Description</h2>
    
    <p>The processed stream at unmarshalling time contains type information to recreate the formerly written objects.
    XStream creates therefore new instances based on these type information.  The crash occurs if this information
    advises XStream to create an instance of the primitive type <em>void</em>.  This situation can only happen if an
    attacker was able to manipulate the incoming data, since such an instance does not exist and cannot be marshalled
    therefore in first place.</p>

    <h2 id="reproduction">Steps to Reproduce</h2>

	<p>The simplest way to demonstrate the problem is with this snippet:</p>
<div class="Source Java"><pre>XStream xstream = new XStream();
xstream.fromXML("&lt;void/&gt;");
</pre></div>

<p>If XStream is configured to read JSON, the equivalent line is:</p>
<div class="Source Java"><pre>xstream.fromXML("{'void':null}");
</pre></div>

<p>However, the problematic type information can be injected at any position in 
the provided stream, in XML just by adding a class attribute:</p>
<div class="Source Java"><pre>xstream.fromXML("&lt;string class='void'&gt;Hello, world!&lt;/string&gt;");
</pre></div>

    <h2 id="impact">Impact</h2>

	<p>The vulnerability may allow a remote attacker to cause a crash on the target system resulting in a denial of
	service only by manipulating the processed input stream.</p>

    <h2 id="workarounds">Workarounds</h2>
	<p>XStream contains since version 1.4.7 a <a href="security.html">security framework</a> to prevent an attack
	described in CVE-2013-7285.  If this framework is properly initialized, it can also be used to suppress the current
	vulnerability by setting:</p>
<div class="Source Java"><pre>xstream.denyTypes(void.class, Void.class);
</pre></div>

	<p>Users of older XStream releases can register an own converter for the <em>void</em> type, that also protects
	against this attack:</p>
<div class="Source Java"><pre>xstream.registerConverter(new Converter() {
  public boolean canConvert(Class type) {
    return Void.class == type || void.class == type;
  }

  public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    throw new ConversionException("Type void cannot have an instance");
  }

  public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
    throw new ConversionException("Type void cannot have an instance");
  }
}, XStream.PRIORITY_VERY_HIGH);
</pre></div>

    <h2 id="credits">Credits</h2>
    
    <p>The vulnerability was discovered and reported by Huijun Chen and Xiaolong Zhu of Huawei Technologies Co., Ltd.</p>
    
  	</body>
 </html>
